#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QThread>
#include <QDebug>
#include <thread>
#include <QRunnable>
#include<QThreadPool>
#include<QtConcurrent/QtConcurrentRun>
#include<QThread>
#include"mythread.h"




//class MyThread : public QThread
//{
//    Q_OBJECT
//public:
//    explicit MyThread(QObject *parent = nullptr);

//protected:
//    void run() override;

//signals:

//};

//MyThread::MyThread(QObject*p):QThread(p){

//}

//void MyThread::run(){

//    qDebug()<<"My Thread running!";

//}

class MyRunnable:public QRunnable{
public:
    virtual ~MyRunnable(){
        qDebug()<<"delete My Runnable";
    }
protected:
    void run() override;
};

void MyRunnable::run(){

    qDebug()<<"My Runnable running";

}

void t3(){
    qDebug()<<"t3 running";
}

int main(int argc, char *argv[])
{

    MyThread t;
    t.start();

    //error
//    MyRunnable t2;
//    QThreadPool::globalInstance()->start(&t2);

    //correct, automatically delete runnable!!!
    QThreadPool::globalInstance()->start(new MyRunnable());

    std::thread t1([]{qDebug()<<"thread t";});
    t1.join();

    QtConcurrent::run(t3);


    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
